<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script th:src="@{/static/main.js}"></script>

    <style>
        .container {
            padding-top: 10px;
        }
        .cover {
            display: inline-block;
            width: 30px;
            height: 30px;
            position: absolute;
            right: 160px;
            top: 9px;
            z-index: 100;
            cursor: pointer;
        }
        .search:hover {
            background-color: honeydew;
        }
    </style>
</head>
<body>
<!--颜醉-->
<!--用户端app主页-->



<div class="container-fluid" id="app" style="margin-top: 5px;margin-bottom: 100px">
    <div class="row" style="margin-top: 10px">
        <div class="col-md-4">

        </div>
        <div class="col-md-2">
            <!--类型列表-->
            <div>
                <select class="form-control search" style="width: 160px" v-model="keyType">
                    <option value=0 style="color: #CCCCCC">请选择店铺类型</option>
                    <option v-for="storeType in storeTypes" :value="storeType.id" v-text="storeType.typeName"></option>
                </select>
            </div>

        </div>

        <div class="col-md-3">
            <form action="" method="post" class="form-inline">
                <div class="form-group">
                    <input v-model="keyName" type="text" name="searchName" class="form-control search" id="search"
                           placeholder="请输入店名">

                    <span class="cover input-icon input-icon-md" @click.prevent="inputClear"
                          style="display: inline">
                                    <span class="glyphicon glyphicon-remove" style="color: rgba(141,134,139,0.48);"></span>
                                </span>
                </div>
                <button type="submit" class="btn btn-default" @click.prevent="toSearch">搜索</button>
            </form>
        </div>

    </div>

    <div class="container" v-if="stores.length<=0">
        <h3 style="text-align: center">很可惜，空空如也~</h3>
    </div>

    <div class="container" v-if="stores.length>0">

        <div class="row">
            <div class="col-md-12">
                <p style="background-color: #458b74 ; color: white; font-size: 30px; padding-left: 10px; border-radius: 4px">所有餐店</p>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6 col-md-12" v-for="store in stores">
                <div class="thumbnail" style="box-shadow: 5px 5px 3px 0px #CCCCCC">
                    <img v-if="!store.storeImg" src="/static/109951166155909486.jpg" alt="..." class="col-sm-2 col-md-2">
                    <img v-if="store.storeImg" :src="store.storeImg" alt="..." class="col-sm-2 col-md-2">
                    <div class="caption text-left">
                        <p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">店铺名:<span v-text="store.storeName">storeName</span></p>
                        <p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">介绍:<span v-text="store.detail">detail</span></p>
                        <p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">经营类型:<span v-text="store.typeName">typeName</span></p>
                        <p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">地址:<span v-text="store.address">address</span></p>
                        <p style="padding-left: 900px;position: relative;bottom: 70px;">
                            <a class="btn btn-success" :href="'/store/toStoreMenu?storeId='+store.id">详情菜单</a> &nbsp;&nbsp;&nbsp;&nbsp;
                        </p>
                    </div>
                </div>
            </div>
        </div>


        <div class="row">
            <div class="col-md-offset-5 col-lg-offset-4col-xl-offset-5">
                <ul class="pagination justify-content-center">
                    <li><a href="javascript:void(0)" @click.prevent="go(currentPage-1)">&laquo;</a></li>
                    <li><a href="javascript:void(0)" v-for="n in totalPages" v-text="n" @click.prevent="go(n)">n</a>
                    </li>
                    <li><a href="javascript:void(0)" @click.prevent="go(currentPage+1)">&raquo;</a></li>
                </ul>
            </div>
        </div>

    </div>


</div>

<script>

    console.log(".........userapp...........")

    let userapp = new Vue({
        el: "#app"
        ,
        data: {
            stores: [],
            storeTypes: [],

            currentPage: 1,
            pageSize: 2,
            total: 0,
            totalPages: 0,

            keyName: '',
            keyType: 0

        }
        ,
        methods: {
            initAllStores() {
                let _this = this;
                let params = {
                    currentPage: _this.currentPage,
                    pageSize: _this.pageSize,
                    keyName: _this.keyName,
                    keyType: _this.keyType
                }
                console.log(params);
                $.post("/store/select", params, function (data) {

                    _this.stores = data.records;
                    _this.currentPage = data.current;
                    _this.pageSize = data.size;
                    //数据总量
                    _this.total = data.total;
                    //总页数
                    _this.totalPages = data.pages;
                })
            }
            ,
            initStoreTypes() {
                let _this = this;
                $.get("/storeType/all",function (data) {
                    _this.storeTypes = data;
                })
            }
            ,
            go(pageNum) {
                //小于1 或者 大于total 或者 仍获取当前页数据 直接返回
                if (pageNum < 1 || pageNum > this.totalPages || pageNum == this.currentPage) {
                    console.log(pageNum + " 无效页码值")
                    return;
                }

                this.currentPage = pageNum;
                this.initAllStores();
            }
            ,
            toSearch() {
                //初始化页数
                this.currentPage = 1;
                this.initAllStores();
            }
            ,
            inputClear() {
                this.keyName = '';
            }
        }
        ,
        created() {
            this.initAllStores();
            this.initStoreTypes();
        }

    });


</script>

</body>
</html>

